package at.ac.tuwien.prog.view;

import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 
 * @author christoph.pickl@student.tuwien.ac.at
 */
public class MainWindow extends JFrame {
	
	private static final Log LOG = LogFactory.getLog(MainWindow.class);
	
	private static final long serialVersionUID = -3356234630430730843L;

	
	public MainWindow(final DataTableModel model, final JMenuBar menuBar) {
		
		this.setTitle("SimulatorX");
		this.setJMenuBar(menuBar);
		this.setResizable(false);
		
		this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
		this.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				MainWindow.this.dispose();
			}
		});
		

		
		final JPanel panel = new JPanel(new BorderLayout());
		
		final DataTable table = new DataTable(model);
		
		panel.add(table, BorderLayout.CENTER);
		
		this.getContentPane().add(panel);

		this.pack();
		
	}

	public Integer readUserInput() { // (final String promptText) {
		final ReadInputDialog dialog = new ReadInputDialog(this, "Enter Number: ");
		dialog.setVisible(true);
		
		if(dialog.isConfirmed() == false) {
			LOG.debug("User canceled input prompt.");
			// do nothing
			return null;
		}
		return dialog.getUserInput();
	}
}
